package com.example.idachuappone;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.example.idachuappone.utils.PrefUtil;
import java.util.ArrayList;
import java.util.List;

public class FristActivity extends BaseActivity {
    PagerAdapter adapter;
    private List<View> pageViews;
    private int version;
    private ViewPager viewPager;

    public FristActivity() {
        this.adapter = new PagerAdapter() {
            public void destroyItem(ViewGroup container, int position, Object object) {
                ((ViewPager) container).removeView((View) FristActivity.this.pageViews.get(position));
            }

            public boolean isViewFromObject(View arg0, Object arg1) {
                return arg0 == arg1;
            }

            public Object instantiateItem(ViewGroup container, int position) {
                ((ViewPager) container).addView((View) FristActivity.this.pageViews.get(position));
                return FristActivity.this.pageViews.get(position);
            }

            public int getCount() {
                return FristActivity.this.pageViews == null ? 0 : FristActivity.this.pageViews.size();
            }
        };
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT, AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT);
        setContentView(R.layout.activity_frist);
        this.version = getIntent().getIntExtra("version", 0);
        this.viewPager = (ViewPager) findViewById(R.id.viewpager);
        initPageAdapter();
        this.viewPager.setAdapter(this.adapter);
    }

    private void initPageAdapter() {
        this.pageViews = new ArrayList();
        View view1 = LinearLayout.inflate(this, R.layout.simple_first_item, null);
        ((ImageView) view1.findViewById(R.id.imageView1)).setImageResource(R.drawable.frist_1);
        this.pageViews.add(view1);
        View view2 = LinearLayout.inflate(this, R.layout.simple_first_item, null);
        ((ImageView) view2.findViewById(R.id.imageView1)).setImageResource(R.drawable.frist_2);
        this.pageViews.add(view2);
        View view3 = LinearLayout.inflate(this, R.layout.simple_first_item, null);
        ((ImageView) view3.findViewById(R.id.imageView1)).setImageResource(R.drawable.frist_3);
        this.pageViews.add(view3);
        View view4 = LinearLayout.inflate(this, R.layout.simple_first_item, null);
        ((ImageView) view4.findViewById(R.id.imageView1)).setImageResource(R.drawable.frist_4);
        Button btn_come = (Button) view4.findViewById(R.id.btn_come);
        btn_come.setVisibility(0);
        btn_come.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                PrefUtil.getInstance(FristActivity.this).setVersion(FristActivity.this.version);
                PrefUtil.getInstance(FristActivity.this).setFrist(false);
                FristActivity.this.startActivity(new Intent(FristActivity.this, LoadingActivity.class));
                FristActivity.this.finish();
            }
        });
        this.pageViews.add(view4);
    }
}
